package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendGoOutRuleAddDTO;
import org.jsola.hr.dto.AttendGoOutRuleUpdateDTO;
import org.jsola.hr.entity.AttendGoOutRuleDO;
import org.jsola.hr.query.AttendGoOutRuleQuery;
import org.jsola.hr.service.IAttendGoOutRuleService;
import org.jsola.hr.vo.AttendGoOutRuleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendGoOutRuleTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendGoOutRuleService attendGoOutRuleService;

    /**
     * 生成add测试数据
     * @return AttendGoOutRuleAddDTO
     */
    public AttendGoOutRuleAddDTO getAttendGoOutRuleAddDTO(){
        AttendGoOutRuleAddDTO attendGoOutRuleAddDTO = new AttendGoOutRuleAddDTO();
        attendGoOutRuleAddDTO.setCollectStartTime(getRandomValue("varchar",10));
        attendGoOutRuleAddDTO.setCollectEndTime(getRandomValue("varchar",10));
        attendGoOutRuleAddDTO.setIsTakePhoto(SafeKit.getInteger(getRandomValue("tinyint",0)));
        attendGoOutRuleAddDTO.setIsAllowLocationPhoto(SafeKit.getInteger(getRandomValue("tinyint",0)));
        return attendGoOutRuleAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendGoOutRuleUpdateDTO
     */
    public AttendGoOutRuleUpdateDTO getAttendGoOutRuleUpdateDTO(AttendGoOutRuleVO attendGoOutRuleVO){
        return attendGoOutRuleService.selectDOById(attendGoOutRuleVO.getId(), SITE_ID).to(AttendGoOutRuleUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendGoOutRuleQuery
     */
    public AttendGoOutRuleQuery getAttendGoOutRuleQuery() {
        AttendGoOutRuleQuery attendGoOutRuleQuery = new AttendGoOutRuleQuery();
        List<AttendGoOutRuleDO> attendGoOutRuleDOList = attendGoOutRuleService.list(new AttendGoOutRuleDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendGoOutRuleDOList)) {
            AttendGoOutRuleDO attendGoOutRuleDO = attendGoOutRuleDOList.get(0);
            attendGoOutRuleQuery = attendGoOutRuleDO.to(AttendGoOutRuleQuery.class);
            if (attendGoOutRuleDO.getGmtCreate() != null) {
                attendGoOutRuleQuery.setGmtCreateStart(DateKit.getBeforeDay(attendGoOutRuleDO.getGmtCreate(),-1));
                attendGoOutRuleQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendGoOutRuleDO.getGmtCreate(),1));
            }
            if (attendGoOutRuleDO.getGmtModified() != null) {
                attendGoOutRuleQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendGoOutRuleDO.getGmtModified(),-1));
                attendGoOutRuleQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendGoOutRuleDO.getGmtModified(),1));
            }
        }
        return attendGoOutRuleQuery;
    }

    /**
     * 保存示例
     * @return AttendGoOutRuleVO
     */
    public AttendGoOutRuleVO saveAttendGoOutRuleExample(){
        AttendGoOutRuleAddDTO addDTO = this.getAttendGoOutRuleAddDTO();
        AttendGoOutRuleVO attendGoOutRuleVO = attendGoOutRuleService.save(addDTO,buildTokenUser());
        return attendGoOutRuleVO;
    }


}

